#include<iostream>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>
using namespace std;

int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        char const argv[] ={
            "ls",
            "-a",
            "-l",
            nullptr
        };
        cout << "pid:" << getpid() << ",execl command begin" << endl;
        //sleep(3);
        //execl("/usr/bin/top", "top", NULL);
        //int n = execl("/usr/bin/pwd", "pwddddddddddddddddd", nullptr);
        //execlp("ls", "ls", "-a", "-l", nullptr);
        execv("/usr/bin/ls", argv);
        //cout << "faild:" << n << endl;
        cout << "pid:" << getpid() << ",execl command end" << endl;
        sleep(3);
    }
    else
    {
        pid_t rid = waitpid(-1, nullptr, 0);
        if(rid > 0)
        {
            cout << "wait success, rid:" << rid <<endl;
        }
    }
    return 0;
}
